#README: advanced version of pic grabber, works through atomic2, modify board= to your need,
#        this modified version searches board=$1 for attachments and downthemall
board=$1

boardurlprefix="http://www.newsmth.net/bbsbfind.php?q=1&board="
boardurlsurfix="&dt=1&ag=on&og="
#delay time=1day, attachment=on, 'og=' means lz & re post / 'og=on' means lz post only
boardurl=$boardurlprefix$board$boardurlsurfix

wget -q --no-cache -O board.htm $boardurl

posthttpaddrprefix="s/httpprefix/http:\/\/www\.newsmth\.net\/atomic2\.php\?act=article\&board="
#act=article is fixed; board= PICTUR*/PIELOV*/MYPHOT*, etc need adjust to your needs from $board=$1
posthttpaddrsurfix="\&id=/g"
posthttpaddr=$posthttpaddrprefix$board$posthttpaddrsurfix

cat board.htm |grep bbsqry | sed  -e "s/.*&id=/httpprefix/g" | sed  -e "s/\">.*//g" > posturl.list 
#sed -i -e "s/httpprefix/http:\/\/www\.newsmth\.net\/atomic2\.php\?act=article\&board=pielove\&id=/g" posturl.list
sed -i -e "$posthttpaddr" posturl.list
#if put $posthttpaddr, i.e. without "$..", crond hangs here... refusing to do the httpprefix replacement, so "$posthttpaddr" is added


#postnum=`cat board.htm |grep bbsqry | tail -1 | sed -e "s/.*&id=//g" | sed -e "s/\">.*//g" ; `
#here we can get all post url list
#posthttp=$httpprefix$postnum 
              
wget -q -O postall.htm -i posturl.list
# can get all list files and sum-up all html into one big file postall.htm
#rm -f posturl.list

cat postall.htm | sed -e "s/<li>/\n/g" | grep "att\.php" |sed -e "s/.*att\.php/http:\/\/www\.newsmth\.net\/att\.php/g" | sed -e "s/' target='_blank'.*//g" > picurl.list
# can get all pic file url into picurl.list
#rm -f postall.htm

wget -q -i picurl.list

renamestrprefix="s/att\.php\?n\.[0-9]*\./"
renamestrsurfix="\_/g"
renamestr=$renamestrprefix$board$renamestrsurfix

find . -name "att*jpg" -exec rename $renamestr {} \;

#depends on perl and rename script
#need to rename att.php?boardid.postid.attachmentid.jpg file name...
rm -f att*png
rm -f att*gif
rm -f att*

#rm -f picurl.list

mogrify -resize 640x480 *.jpg                               
#make it universal size

